<?php
include_once("BmCommon.php");

/**
 * Created by PhpStorm.
 * User: aoxiangli
 * Date: 2017/6/27 14:47
 * Description: 管理后台统一api
 */
class BmApi extends BmCommon
{
    public function checkLogin()
    {
        $this->tools->checkToken($this->pre_token);
        $username = $this->input->post("username") != null ? $this->input->post("username") : "";
        $password = $this->input->post("password") != null ? $this->input->post("password") : "";
        if (!$username) {
            $this->tools->echoJson($this->errorcode->noUserName);
        }
        if (!$password) {
            $this->tools->echoJson($this->errorcode->noPwd);
        }
        $sql = "SELECT * FROM admin WHERE username='$username'";
        $result = $this->db->query($sql);
        $row = $result->row_array();
        if ($row) {
            $password = md5(md5($password . $row['salt']));
            if ($row['password'] != $password) {
                $this->tools->echoJson($this->errorcode->passwordWrong);
            }
            $user = array('username' => $username, 'uid' => $row['id']);
            $this->session->set_userdata('adminUser', $user, 86400);
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->notExistUser);
        }
    }

    //用户列表
    public function userList()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $realname = $this->input->post("realname") != null ? $this->input->post("realname") : "";
        $title = $this->input->post("title") != null ? $this->input->post("title") : "";
        $expert = $this->input->post("expert") != null ? $this->input->post("expert") : "";
        $auth_status = $this->input->post("auth_status") != null ? $this->input->post("auth_status") : 0;
        $account_status = $this->input->post("account_status") != null ? $this->input->post("account_status") : 0;
        $begin_online_date = $this->input->post("begin_online_date") != null ? $this->input->post("begin_online_date") : "";
        $end_online_date = $this->input->post("end_online_date") != null ? $this->input->post("end_online_date") : "";
        $page = $this->input->get('per_page') != null ? $this->input->get('per_page') : 1;
        $page_size = 15;
        $where = "1=1";
        if ($realname) {
            $where .= " AND realname LIKE '%{$realname}%'";
        }

        if ($title) {
            $where .= " AND title LIKE '%{$title}%'";
        }

        if ($expert) {
            $where .= " AND expert LIKE '%{$expert}%'";
        }

        if ($auth_status) {
            $where .= " AND auth_status IN ({$auth_status})";
        }

        if ($account_status) {
            $where .= " AND account_status = '{$account_status}'";
        }

        if ($begin_online_date) {
            $where .= " AND DATE_FORMAT(recent_online_time,'%Y-%m-%d') >= '{$begin_online_date}'";
        }

        if ($end_online_date) {
            $where .= " AND DATE_FORMAT(recent_online_time,'%Y-%m-%d') <= '{$end_online_date}'";
        }
        list($total, $data) = parent::commonList($where, "users", $page, $page_size, '', 'id,realname,mobile,recent_online_time,auth_status,account_status,has_answer,weight');
        foreach ($data AS $key => $val) {
            if ($val['recent_online_time'] == NULL) {
                $data[$key]['recent_online_time'] = "0000-00-00";
            }
        }
        if ($total == 0) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->success, array('total' => $total, 'data' => $data, 'page_size' => $page_size));
        }
    }

    //用户详细资料
    public function userInfo()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->input->post("id") : 5;
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        $sql = "SELECT realname,a.id,account_status,IFNULL(company,'') AS company,IFNULL(job,'') AS job,IFNULL(country,'') AS country,IFNULL(province,'') AS province,IFNULL(city,'') AS city ,id_card,mobile,IFNULL(a.title,'') AS title,expert,earnings,IFNULL(headimgurl,'') AS headimgurl,IFNULL(id_card_url,'') AS id_card_url,has_answer,no_answer,a.level_id FROM users a LEFT JOIN user_level b ON a.level_id=b.id WHERE a.id={$id}";
        $result = $this->db->query($sql);
        $row = $result->row_array();
        $sql = "SELECT id,title FROM user_level ";
        $result = $this->db->query($sql);
        $level = $result->result_array();
        //获取reason
        $sql = "SELECT id,is_reply,reason FROM user_reason_log WHERE is_deleted=0";
        $result = $this->db->query($sql);
        $reason = $result->result_array();
        if ($row) {
            $this->tools->echoJson($this->errorcode->success, array('info' => $row, 'level' => $level, 'reason' => $reason));
        } else {
            $this->tools->echoJson($this->errorcode->success);
        }
    }

    /**
     * 修改账户状态
     * submit_account_status:1=>认证中驳回 2=>重新提交资料驳回 3=>冻结账户 4=>通过（认证通过，审核资料通过，解冻）
     */
    public function modifyAccountStatus()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->input->post("id") : 0;
        $level_id = $this->input->post("level_id") != null ? $this->input->post("level_id") : 0;
        $block_begin_time = $this->input->post("block_begin_time") != null ? $this->input->post("block_begin_time") : '0000-00-00';
        $block_end_time = $this->input->post("block_end_time") != null ? $this->input->post("block_end_time") : '0000-00-00';
        $submit_account_status = $this->input->post("submit_account_status") != null ? $this->input->post("submit_account_status") : 0;
        $reason = $this->input->post("reason") != null ? $this->input->post("reason") : "";
        $user = array();
        $sql = "SELECT * FROM users WHERE id={$id}";
        $result = $this->db->query($sql);
        $base_info = $result->row_array();
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        $this->db->trans_start();
        if ($submit_account_status == 1) {
            $account_status = 3;
            $user['auth_status'] = 1;
            $log['is_deleted'] = 1;
            $this->db->where("uid", $id);
            $this->db->update("user_reason_log", $log);
            $this->newUserLogs($id, $reason, $submit_account_status);
        } else if ($submit_account_status == 2) {
            $account_status = 3;
            $log['is_deleted'] = 1;
            $this->db->where("uid", $id);
            $this->db->update("user_reason_log", $log);
            $this->newUserLogs($id, $reason, $submit_account_status);
        } else if ($submit_account_status == 3) {
            if ($base_info['account_status'] != 4) {
                $account_status = 5;
            }
            if (($block_begin_time == "0000-00-00" || $block_end_time == "0000-00-00") && $block_begin_time >= $block_end_time) {
                $this->tools->echoJson($this->errorcode->noValidBlockTime);
            }
            $user['block_begin_time'] = $block_begin_time;
            $user['block_end_time'] = $block_end_time;
            $sql = "UPDATE user_reason_log SET is_deleted=1 WHERE log_type!=3";
            $this->db->query($sql);
            $this->newUserLogs($id, $reason, $submit_account_status);
        } else if ($submit_account_status == 4) {
            $user['auth_status'] = 3;
            $account_status = 6;
            $log['is_deleted'] = 1;
            $this->db->where("uid", $id);
            $this->db->update("user_reason_log", $log);
        } else {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        }

        $user['account_status'] = $account_status;
        if ($level_id) {
            $user['level_id'] = $level_id;
        }
        $this->db->where("id", $id);
        $this->db->update("users", $user);
        $this->db->trans_complete();
        if ($this->db->trans_status() !== FALSE) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        }
    }

    /**
     * 修改答主资料
     * modify_type:1=>修复全部 2=>简易修改
     */
    public function modifyUserInfo()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->input->post("id") : 5;
        $modify_type = $this->input->post("modify_type") != null ? $this->input->post("modify_type") : 1;
        $company = $this->input->post("company") != null ? $this->input->post("company") : '';
        $job = $this->input->post("job") != null ? $this->input->post("job") : '';
        $province = $this->input->post("province") != null ? $this->input->post("province") : '';
        $city = $this->input->post("city") != null ? $this->input->post("city") : '';
        $mobile = $this->input->post("mobile") != null ? $this->input->post("mobile") : '';
        $title = $this->input->post("title") != null ? $this->input->post("title") : '';
        $earnings = $this->input->post("earnings") != null ? $this->input->post("earnings") : 0;
        $expert = $this->input->post("expert") != null ? $this->input->post("expert") : '';
        $level_id = $this->input->post("level_id") != null ? $this->input->post("level_id") : 0;
        $weight = $this->input->post("weight") != null ? $this->input->post("weight") : 0;
        list($id_card_url, $id_card_width, $id_card_height) = $this->tools->savePic('id_card', 'pic', 1024);
        list($headimgurl, $headimg_width, $headimg_height) = $this->tools->savePic('headimgurl', 'pic', 1024);
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }

        if (!$earnings && $modify_type == 1) {
            $this->tools->echoJson($this->errorcode->noEarnings);
        }

        if (!$level_id && $modify_type == 1) {
            $this->tools->echoJson($this->errorcode->noLevelID);
        }

        $arg = array('company', 'job', 'province', 'city', 'mobile', 'title', 'expert', 'earnings', 'level_id', 'id_card_url', 'headimgurl', 'weight');
        foreach ($arg AS $key => $val) {
            if ($$val) {
                $user[$val] = $$val;
            }
        }
        $this->db->where("id", $id);
        $result = $this->db->update("users", $user);
        if ($result) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        }
    }

    //获取问题列表
    public function questionList()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $status = $this->input->post("status") != null ? $this->db->escape_str($this->input->post("status")) : 0;
        $is_deleted = $this->input->post("is_deleted") != null ? $this->db->escape_str($this->input->post("is_deleted")) : 0;
        $hide = $this->input->post("hide") != null ? $this->db->escape_str($this->input->post("hide")) : 0;
        $content = $this->input->post("content") != null ? $this->db->escape_str($this->input->post("content")) : "";
        $realname = $this->input->post("realname") != null ? $this->db->escape_str($this->input->post("realname")) : "";
        $page = $this->input->post('per_page') != null ? $this->db->escape_str($this->input->post('per_page')) : 1;
        $page_size = 15;
        $where = "1=1";
        if ($status) {
            $where .= " AND status = {$status}";
        }

        if ($is_deleted) {
            $where .= " AND is_deleted = {$is_deleted}";
        }

        if ($hide) {
            $where .= " AND is_hided = {$hide}";
        }

        if ($content) {
            $where .= " AND content LIKE '%{$content}%'";
        }

        if ($realname) {
            $where .= " AND realname LIKE '%{$realname}%'";
        }

        list($total, $data) = parent::commonList($where, "questions a", $page, $page_size, 'left join users b ON a.answerer = b.id ', 'a.id,realname,content,status,watch_count,a.weight,price,a.create_time,a.is_deleted,a.is_hided');
        if ($total == 0) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->success, array('total' => $total, 'data' => $data, 'page_size' => $page_size));
        }
    }

    //获取问题详情
    public function questionInfo()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->db->escape_str($this->input->post("id")) : 644;
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        $sql = "SELECT a.id,a.content,status,watch_count,free_time,b.content AS answer,b.create_time AS answer_time FROM questions a LEFT JOIN question_answer b ON a.id=b.qid WHERE a.id={$id}";
        $result = $this->db->query($sql);
        $post = $result->row_array();
        if ($post) {
            $sql = "SELECT COUNT(*) AS c FROM question_like WHERE qid={$id} AND status=1";
            $result = $this->db->query($sql);
            $row = $result->row_array();
            $post['useful'] = $row['c'];
            $sql = "SELECT COUNT(*) AS c FROM question_like WHERE qid={$id} AND status=0";
            $result = $this->db->query($sql);
            $row = $result->row_array();
            $post['unuseful'] = $row['c'];
            $this->tools->echoJson($this->errorcode->success, array('post' => $post));
        } else {
            $this->tools->echoJson($this->errorcode->success);
        }
    }

    //保存问题详情
    public function questionSave()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->db->escape_str($this->input->post("id")) : 0;
        $free_time = $this->input->post("free_time") != null ? $this->db->escape_str($this->input->post("free_time")) : '0000-00-00';
        $status = $this->input->post("status") != null ? $this->db->escape_str($this->input->post("status")) : 0;
        $weight = $this->input->post("weight") != null ? $this->db->escape_str($this->input->post("weight")) : 1;
        $answer = $this->input->post("answer") != null ? $this->db->escape_str($this->input->post("answer")) : '';
        $data = array();
        $answer_data = array();
        $result = true;
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        if ($free_time) {
            $data['free_time'] = $free_time;
        }

        if ($status) {
            $data['status'] = $status;
        }

        if ($weight) {
            $data['weight'] = $weight;
        }

        if ($answer) {
            $answer_data['content'] = $answer;
        }
        if ($data) {
            $this->db->where("id", $id);
            $result = $this->db->update("questions", $data);
        }
        if ($answer_data) {
            $this->db->where("qid", $id);
            $result = $this->db->update("question_answer", $answer_data);
        }
        if ($result) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        }
    }

    //删除问题
    public function questionDel()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->db->escape_str($this->input->post("id")) : 0;
        $reason = $this->input->post("reason") != null ? $this->db->escape_str($this->input->post("reason")) : '';
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        $data['is_deleted'] = 1;
        $data['reason'] = $reason;
        $this->db->where("id", $id);
        $result = $this->db->update("questions", $data);
        if ($result) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        }
    }

    //隐藏问题
    public function questionHide()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->db->escape_str($this->input->post("id")) : 0;
        $hide = $this->input->post("hide") != null ? $this->db->escape_str($this->input->post("hide")) : 0;
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        $data['is_hided'] = $hide;
        $this->db->where("id", $id);
        $result = $this->db->update("questions", $data);
        if ($result) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        }
    }

    //获取搜索词
    public function getKeywordsList()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $sql = "SELECT id,content FROM keywords WHERE type=1";
        $result = $this->db->query($sql);
        $keywords = $result->result_array();
        $sql = "SELECT id,content FROM bm_keywords_history WHERE type=1 GROUP BY content LIMIT 20";
        $result = $this->db->query($sql);
        $history_keywords = $result->result_array();
        $this->tools->echoJson($this->errorcode->success, array('keywords' => $keywords, 'history_keywords' => $history_keywords));
    }

    //增加搜索词
    public function addKeyWords()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $keywords = $this->input->post("keywords") != null ? $this->input->post("keywords") : array();
        $type = $this->input->post("type") != null ? $this->db->escape_str($this->input->post("type")) : 1;
        if (empty($keywords)) {
            $this->tools->echoJson($this->errorcode->noKeywords);
        }
        $keywords = array_unique($keywords);
        $_keywords = array();
        foreach ($keywords AS $key => $val) {
            $_keywords[] = array('type' => $type, 'content' => $val);
        }
        $this->db->trans_start();
        $sql = "DELETE FROM keywords WHERE type='$type'";
        $this->db->query($sql);
        $this->db->insert_batch("keywords", $_keywords);
        $this->db->insert_batch("bm_keywords_history", $_keywords);
        $this->db->trans_complete();
        if ($this->db->trans_status() === FALSE) {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        } else {
            $this->tools->echoJson($this->errorcode->success);
        }
    }

    //增加修改广告位
    public function saveAd()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->input->post("id") : 0;
        $title = $this->input->post("title") != null ? $this->input->post("title") : '';
        $link = $this->input->post("link") != null ? $this->input->post("link") : '';
        $sort = $this->input->post("sort") != null ? $this->input->post("sort") : 0;
        $ad_type = $this->input->post("ad_type") != null ? $this->input->post("ad_type") : 1;
        $modify_type = $this->input->post("modify_type") != null ? $this->input->post("modify_type") : 1;
        if (!$title && $modify_type == 1) {
            $this->tools->echoJson($this->errorcode->noTitle);
        }
        if (!$ad_type && $modify_type == 1) {
            $this->tools->echoJson($this->errorcode->noType);
        }
        if ($modify_type == 2 && !$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        list($pic_url, $width, $height) = $this->tools->savePic('pic', 'pic', 1024);
        $data = array();

        if ($ad_type) {
            $data['type'] = $ad_type;
        }

        if ($title) {
            $data['title'] = $title;
        }

        if ($link) {
            $data['link'] = $link;
        }

        if ($pic_url) {
            $data['pic_url'] = $pic_url;
        }

        if ($sort) {
            $data['sort'] = $sort;
        }
        if ($id) {
            $this->db->where('id', $id);
            $result = $this->db->update("advertisement", $data);
        } else {
            $data['createtime'] = date("Y-m-d H:i:s");
            $result = $this->db->insert("advertisement", $data);
        }
        if (!$result) {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        } else {
            $this->tools->echoJson($this->errorcode->success);
        }
    }

    //删除广告位
    public function adDel()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->input->post("id") : 0;
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        $data['is_deleted'] = 1;
        $this->db->where("id", $id);
        $result = $this->db->update("advertisement", $data);
        if (!$result) {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        } else {
            $this->tools->echoJson($this->errorcode->success);
        }
    }

    //广告位列表
    public function adList()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $ad_type = $this->input->post("ad_type") != null ? $this->db->escape_str($this->input->post("ad_type")) : 0;
        $title = $this->input->post("title") != null ? $this->db->escape_str($this->input->post("title")) : '';
        $page = $this->input->get('per_page') != null ? $this->db->escape_str($this->input->get('per_page')) : 1;
        $page_size = 15;
        $where = "1=1 AND is_deleted=0";
        if ($title) {
            $where .= " AND title LIKE '%{$title}%'";
        }
        if ($ad_type) {
            $where .= " AND type = '$ad_type'";
        }
        list($total, $data) = parent::commonList($where, "advertisement", $page, $page_size, '', 'id,pic_url,title,link,type,sort');
        if ($total == 0) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->success, array('total' => $total, 'data' => $data, 'page_size' => $page_size));
        }
    }

    //编辑广告位
    public function adInfo()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->input->post("id") : 0;
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        $sql = "SELECT id,pic_url,title,link,type,sort FROM advertisement WHERE id='$id'";
        $result = $this->db->query($sql);
        $row = $result->row_array();
        if ($row) {
            $this->tools->echoJson($this->errorcode->success, array('data' => $row));
        } else {
            $this->tools->echoJson($this->errorcode->success);
        }
    }

    //获取feedback list
    public function feedbackList()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $page = $this->input->post('per_page') != null ? $this->db->escape_str($this->input->post('per_page')) : 1;
        $is_reply = $this->input->post('is_reply') != null ? $this->db->escape_str($this->input->post('is_reply')) : 0;
        $page_size = 15;
        $where = "1=1";
        if ($is_reply) {
            $where .= " AND is_reply='{$is_reply}'";
        }
        list($total, $data) = parent::commonList($where, "feedback a", $page, $page_size, 'LEFT JOIN feedback_reply b ON a.id=b.fid', 'a.id,a.content,is_reply,IFNULL(b.content,"") AS reply_content', 'a.id DESC');
        if ($total == 0) {
            $this->tools->echoJson($this->errorcode->success);
        } else {
            $this->tools->echoJson($this->errorcode->success, array('total' => $total, 'data' => $data, 'page_size' => $page_size));
        }
    }

    //获取feedback详情
    public function feedbackInfo()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->input->post("id") : 0;
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        $sql = "SELECT a.content,is_reply,IFNULL(b.content,'') AS reply_content from feedback a LEFT JOIN feedback_reply b ON a.id=b.fid WHERE a.id='{$id}' ORDER BY b.id DESC LIMIT 1";
        $result = $this->db->query($sql);
        $row = $result->row_array();
        if ($row) {
            $this->tools->echoJson($this->errorcode->success, array('data' => $row));
        } else {
            $this->tools->echoJson($this->errorcode->success);
        }
    }

    //保存feedback
    public function saveFeedback()
    {
        parent::checkSession();
        $this->tools->checkToken($this->pre_token);
        $id = $this->input->post("id") != null ? $this->input->post("id") : 0;
        $content = $this->input->post("content") != null ? $this->input->post("content") : '';
        if (!$id) {
            $this->tools->echoJson($this->errorcode->noIDS);
        }
        if (!$content) {
            $this->tools->echoJson($this->errorcode->noContent);
        }
        $sql = "SELECT wx_openid FROM feedback a LEFT JOIN users b ON a.uid=b.id WHERE b.id='{$id}'";
        $result = $this->db->query($sql);
        $base_info = $result->row_array();
        $this->db->trans_start();
        $data['admin_id'] = $this->login_user_id;
        $data['fid'] = $id;
        $data['content'] = $content;
        $this->db->insert("feedback_reply", $data);
        $data = array();
        $data['is_reply'] = 2;
        $this->db->where("id", $id);
        $this->db->update("feedback", $data);
        //todo 发送微信消息
        $this->db->trans_complete();
        if ($this->db->trans_status() === FALSE) {
            $this->tools->echoJson($this->errorcode->noReasonWrong);
        } else {
            $this->tools->echoJson($this->errorcode->success);
        }
    }

    protected function newUserLogs($id, $reason, $log_type)
    {
        $log['uid'] = $id;
        $log['reason'] = $reason;
        $log['log_type'] = $log_type;
        $log['admin_uid'] = $this->login_user_id;
        $log['is_reply'] = 0;
        $this->db->insert("user_reason_log", $log);
    }
}